<template>
    <div class="iframe">
        <div class="i-title">
            <h3>组件A</h3>
        </div>
        <div class="i-tip">
            {{ info.name }},{{info.age}}
        </div>
        <div class="i-tip">
            <el-button @click="send2">发送</el-button>
        </div>
    </div>
</template>
<script>
import { reactive, onMounted } from "vue"
import pubsub from "pubsub-js"
export default {
    setup() {
        let info = reactive({
            name: "...",
            age:18
        })
        function send2() {
            pubsub.publish("Age", info.age)
        }
        onMounted(() => {
            //订阅
            pubsub.subscribe("getName", (prop, data) => {
                console.log(prop, data)
                info.name = data;
            })
        })
        return {
            info,
            send2
        }
    }
}
</script>
